﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Client.ServiceReference;

namespace Client
{
    enum LoaiTimKiem
    {
        OneWay,
        RoundTrip
    };
    public partial class Form1 : Form
    {
        string[] DataNgayDi = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
        string[] cbb2 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
        string[] DataNgayVe = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" };
        string[] DataThangDi = { "2012-12", "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06", "2013-07", "2013-08", "2013-09", "2013-10", "2013-11" };
        string[] cbb1 = { "2012-12", "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06", "2013-07", "2013-08", "2013-09", "2013-10", "2013-11" };
        string[] DataThangVe = { "2012-12", "2013-01", "2013-02", "2013-03", "2013-04", "2013-05", "2013-06", "2013-07", "2013-08", "2013-09", "2013-10", "2013-11" };
        string[] DataDiemDi = { "Buôn Ma Thuột (BMV)", "Cà Mau (CAH)", "Côn Đảo (VCS)", "Cần Thơ (VCA)", "Huế (HUI)", "Hà Nội (HAN)", "Hải Phòng (HPH)", "Nha Trang (NHA)", "Phú Quốc (PQC)", "Pleiku (PXU)", "Quy Nhơn (UIH)", "Rạch Giá (VKG)", "Tam Kỳ (VCL)", "Tp Hồ Chí Minh (SGN)", "Tuy Hòa (TBB)", "Vinh (VII)", "Điện Biên (DIN)", "Đà Lạt (DLI)", "Đà Nẵng (DAD)", "Đồng Hới (VDH)" };
        string[] DataDiemDen = { "Buôn Ma Thuột (BMV)", "Cà Mau (CAH)", "Côn Đảo (VCS)", "Cần Thơ (VCA)", "Huế (HUI)", "Hà Nội (HAN)", "Hải Phòng (HPH)", "Nha Trang (NHA)", "Phú Quốc (PQC)", "Pleiku (PXU)", "Quy Nhơn (UIH)", "Rạch Giá (VKG)", "Tam Kỳ (VCL)", "Tp Hồ Chí Minh (SGN)", "Tuy Hòa (TBB)", "Vinh (VII)", "Điện Biên (DIN)", "Đà Lạt (DLI)", "Đà Nẵng (DAD)", "Đồng Hới (VDH)" };
        string[] cbb3 = { "Buôn Ma Thuột (BMV)", "Cà Mau (CAH)", "Côn Đảo (VCS)", "Cần Thơ (VCA)", "Huế (HUI)", "Hà Nội (HAN)", "Hải Phòng (HPH)", "Nha Trang (NHA)", "Phú Quốc (PQC)", "Pleiku (PXU)", "Quy Nhơn (UIH)", "Rạch Giá (VKG)", "Tam Kỳ (VCL)", "Tp Hồ Chí Minh (SGN)", "Tuy Hòa (TBB)", "Vinh (VII)", "Điện Biên (DIN)", "Đà Lạt (DLI)", "Đà Nẵng (DAD)", "Đồng Hới (VDH)" };
        private DataSet dsCB;
        private DataSet dsCBKH;
        private DataSet dsCB3;

        int flag = 0;
        Form2 f2;
        List<string> cb;
        List<string> cbkh;
        List<string> cb3;
        
        ServiceReference.ServiceSoapClient objCB = new ServiceSoapClient();
        
        
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            label5.Text = "Dang xu ly";
            string loai = "";
            string diemdi, diemden, ngaydi, ngayve, thangdi, thangve, diemtrunggian, ngaytrunggian, thangtrunggian;
            
            if (radioKhuHoi.Checked)
                loai = "RoundTrip";
            if (radioMotChieu.Checked)
                loai = "OneWay";
            if (radioNhieuChang.Checked)
                loai = "OneWay";
            diemdi = CbbDiemDi.Text;
            diemden = CbbDiemDen.Text;
            ngaydi = CbbNgayDi.Text;
            ngayve = CbbNgayVe.Text;
            thangdi = CbbThangDi.Text;
            thangve = CbbThangVe.Text;
            diemtrunggian = comboBox3.Text;
            ngaytrunggian = comboBox2.Text;
            thangtrunggian = comboBox1.Text;
            
                if (!radioNhieuChang.Checked)
                {
                    objCB.SearchAll(loai, diemdi, ngaydi, thangdi, diemden, ngayve, thangve);
                    objCB.LoadViNa();
                }
                else
                {
                    objCB.Search3Chang(loai, diemdi, ngaydi, thangdi, diemden, ngayve, thangve, diemtrunggian, ngaytrunggian, thangtrunggian);
                    objCB.LoadAll();
                }
           
            LoadCB();
        }
        public void LoadCB()
        {
            try
            {
                
                dsCB = new DataSet();
                dsCBKH = new DataSet();
                dsCB3 = new DataSet();
                dsCB = objCB.DanhSachCB();
                dsCBKH = objCB.DanhSachCBKH();
                dsCB3 = objCB.DanhSachCB3();
                
                dataGridView1.DataSource = dsCB.Tables[0].DefaultView;
                dataGridView2.DataSource = dsCBKH.Tables[0].DefaultView;
                dataGridView3.DataSource = dsCB3.Tables[0].DefaultView;
                label5.Text = "Thành Công";
            }
            catch (Exception ex)
            {
                 MessageBox.Show(ex.ToString());            
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'ttcb1DataSet.thongtincb' table. You can move, or remove it, as needed.
           
            CbbNgayDi.DataSource = DataNgayDi;
            CbbNgayVe.DataSource = DataNgayVe;
            CbbThangDi.DataSource = DataThangDi;
            CbbThangVe.DataSource = DataThangVe;
            CbbDiemDi.DataSource = DataDiemDi;
            CbbDiemDen.DataSource = DataDiemDen;
            comboBox1.DataSource = cbb1;
            comboBox2.DataSource = cbb2;
            comboBox3.DataSource = cbb3;
            CbbDiemDi.Text = "Hà Nội (HAN)";
            CbbDiemDen.Text = "Tp Hồ Chí Minh (SGN)";
            CbbNgayDi.Text = "31";
            CbbNgayVe.Text = "1";
            CbbThangVe.Text = "2013-01";
            radioMotChieu.Checked = true;

            comboBox1.Visible = false;
            comboBox2.Visible = false;
            comboBox3.Visible = false;
            label8.Visible = false;
            label9.Visible = false;
            button2.Visible = false;
            this.ClientSize = new System.Drawing.Size(836, 562);
        }

        private void radioNhieuChang_CheckedChanged(object sender, EventArgs e)
        {
            comboBox1.Visible = true;
            comboBox2.Visible = true;
            comboBox3.Visible = true;
            label8.Visible = true;
            label9.Visible = true;
            this.ClientSize = new System.Drawing.Size(836, 752);
            label6.Text = "Chặng 1";
            label7.Text = "Chặng 2";
            label10.Text = "Chặng 3";
            label4.Visible = true;
            CbbNgayVe.Visible = true;
            CbbThangVe.Visible = true;
        }

        private void radioMotChieu_CheckedChanged(object sender, EventArgs e)
        {
            comboBox1.Visible = false;
            comboBox2.Visible = false;
            comboBox3.Visible = false;
            label8.Visible = false;
            label9.Visible = false;
            this.ClientSize = new System.Drawing.Size(836, 372);
            label6.Text = "Lượt đi";
            label4.Visible = false;
            CbbNgayVe.Visible = false;
            CbbThangVe.Visible = false;
        }

        private void radioKhuHoi_CheckedChanged(object sender, EventArgs e)
        {
            label4.Visible = true;
            CbbNgayVe.Visible = true;
            CbbThangVe.Visible = true;
            comboBox1.Visible = false;
            comboBox2.Visible = false;
            comboBox3.Visible = false;
            label8.Visible = false;
            label9.Visible = false;
            this.ClientSize = new System.Drawing.Size(836, 562);
            label6.Text = "Lượt đi";
            label7.Text = "Lượt về";
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int i = e.RowIndex;
            int j = e.ColumnIndex;
            cb = new List<string>();

            cb.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[2].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[3].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[4].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[5].Value.ToString());
            cb.Add(dataGridView1.Rows[i].Cells[6].Value.ToString());

            MessageBox.Show("Đã chọn chuyến bay này!");
            flag++;
            if (radioKhuHoi.Checked == true && flag == 2)
                this.button2.Visible = true;
            if (radioMotChieu.Checked == true && flag == 1)
                this.button2.Visible = true;            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            flag = 0;
            f2 = new Form2();

            if (radioMotChieu.Checked == true)
            {
                f2.hang = cb[0];
                f2.diemdi = cb[1];
                f2.diemden = cb[2];
                f2.thoigiandi = cb[3];
                f2.thoigianden = cb[4];
                f2.gia = cb[5];
                f2.chuyenbay = cb[6];

                f2.hangkh = "";
                f2.diemdikh = "";
                f2.diemdenkh = "";
                f2.thoigiandikh = "";
                f2.thoigiandenkh = "";
                f2.giakh = "";
                f2.chuyenbaykh = "";

                f2.hang3 = "";
                f2.diemdi3 = "";
                f2.diemden3 = "";
                f2.thoigiandi3 = "";
                f2.thoigianden3 = "";
                f2.gia3 = "";
                f2.chuyenbay3 = "";

                f2.flag = 0;
            }
            if (radioKhuHoi.Checked == true)
            {
                f2.hang = cb[0];
                f2.diemdi = cb[1];
                f2.diemden = cb[2];
                f2.thoigiandi = cb[3];
                f2.thoigianden = cb[4];
                f2.gia = cb[5];
                f2.chuyenbay = cb[6];

                f2.hangkh = cbkh[0];
                f2.diemdikh = cbkh[1];
                f2.diemdenkh = cbkh[2];
                f2.thoigiandikh = cbkh[3];
                f2.thoigiandenkh = cbkh[4];
                f2.giakh = cbkh[5];
                f2.chuyenbaykh = cbkh[6];

                f2.hang3 = "";
                f2.diemdi3 = "";
                f2.diemden3 = "";
                f2.thoigiandi3 = "";
                f2.thoigianden3 = "";
                f2.gia3 = "";
                f2.chuyenbay3 = "";

                f2.flag = 1;
            }

            if (radioNhieuChang.Checked == true)
            {
                f2.hang = cb[0];
                f2.diemdi = cb[1];
                f2.diemden = cb[2];
                f2.thoigiandi = cb[3];
                f2.thoigianden = cb[4];
                f2.gia = cb[5];
                f2.chuyenbay = cb[6];

                f2.hangkh = cbkh[0];
                f2.diemdikh = cbkh[1];
                f2.diemdenkh = cbkh[2];
                f2.thoigiandikh = cbkh[3];
                f2.thoigiandenkh = cbkh[4];
                f2.giakh = cbkh[5];
                f2.chuyenbaykh = cbkh[6];

                f2.hang3 = cb3[0];
                f2.diemdi3 = cb3[1];
                f2.diemden3 = cb3[2];
                f2.thoigiandi3 = cb3[3];
                f2.thoigianden3 = cb3[4];
                f2.gia3 = cb3[5];
                f2.chuyenbay3 = cb3[6];

                f2.flag = 2;
            }
            f2.Show();
            this.button2.Visible = false;
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView2_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int i = e.RowIndex;
            int j = e.ColumnIndex;
            cbkh = new List<string>();

            cbkh.Add(dataGridView2.Rows[i].Cells[0].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[1].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[2].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[3].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[4].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[5].Value.ToString());
            cbkh.Add(dataGridView2.Rows[i].Cells[6].Value.ToString());

            MessageBox.Show("Đã chọn chuyến bay này!");
            flag++;
            if (radioKhuHoi.Checked == true && flag == 2)
                this.button2.Visible = true;
        }

        private void dataGridView3_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int i = e.RowIndex;
            int j = e.ColumnIndex;

            cb3 = new List<string>();

            cb3.Add(dataGridView3.Rows[i].Cells[0].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[1].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[2].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[3].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[4].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[5].Value.ToString());
            cb3.Add(dataGridView3.Rows[i].Cells[6].Value.ToString());

            MessageBox.Show("Đã chọn chuyến bay này!");
            flag++;
            if (radioNhieuChang.Checked == true && flag == 3)
                this.button2.Visible = true;
        }

    }
}